package process;

public class BK_UDPSENd {

}

/*//	private String m_host = "10.0.2.2";
	private int m_port = 8282;
	
//	private String m_Path = "/sdcard";
	//private String m_filename = "b.ppt";
	private int size = 1400;
	private String m_Start = "SendFileName";
	private String m_Content = "SendContenFile";
	private String m_End = "Kết thúc";
	private InputStream is;
	private FileInputStream fis;
	private BufferedInputStream bis;
	private String g_m_Path;
	private String g_m_filename;
	String[]g_ArrayOfIP;
	SendAllFile send = new SendAllFile();
	private String tempIP;
	private int tempPort;
	private String m_Start2;
	private int num;
	// Khue has mod
*/	
	/*public void SendUsingUDP(String m_Path ,String m_filename,String[] ArrayOfIP)
	{
		// khue has mod here
		//String thongbao ="";
		//SendAllFile send = new SendAllFile();
		int port = 8080;
		g_m_Path=m_Path;
		g_m_filename=m_filename;
		g_ArrayOfIP=ArrayOfIP;
		try {
			Thread uThread=new Thread(new UDP_Send());
			uThread.start();
		} catch (Exception e) {
			// TODO: handle exception
		}
			
		
		
	}

	public class UDP_Send implements Runnable{
		
		final Handler myHandler = new Handler();
		
		@Override
		public void run() {
			// TODO Auto-generated method stub
			(new Thread(new Runnable() {
				
				@Override
				synchronized public void run() {
					// TODO Auto-generated method stub
					final String l_Path=g_m_Path;
					final String l_Filename= g_m_filename;
					int port =8080;
					final int i_port=m_port;
					 m_Start2=m_Start;
					for(int i=0;i<g_ArrayOfIP.length;i++)
					{
						
						num=i;
							myHandler.post(new Runnable() {
								
								@Override
								synchronized public void run() {
									// TODO Auto-generated method stub
									tempIP=g_ArrayOfIP[num];
									String m_host=tempIP;
									tempPort=i_port;
									int kq = send.SendInfoStartSendUDP(m_host, i_port, m_Start2);
									if(kq==1)
									{
										int ports = 8181;
											int kq1 = send.sendfilename(m_host, ports, l_Filename);
											
											if(kq1!=0)
											{
												int portss = 8383;
											//	int kq2 = send.SendfilenameUDP(m_host, i_port, m_Content);
												int kq3 = send.SenContentFile(l_Path, l_Filename, m_host, portss);
												//thongbao = "successful"+kq3;
												
											}
											else
											{
												//thongbao = "unsuccessful";
											}
										 }
								}
								
							});	
					}
				}
			})).start();
		}
		
	}
}




public String SendUsingUDP(String m_Path ,String m_filename,String[] ArrayOfIP)
{
	
	String thongbao ="";
	SendAllFile send = new SendAllFile();
	int port = 8080;
	for(int i=0;i<ArrayOfIP.length;i++)
	{
		
	String m_host=ArrayOfIP[i];
	int kq = send.SendInfoStartSendUDP(m_host, i_port, m_Start);
	
//	int kq3 = send.sendInfoEndSend(m_host, i_port, m_End);
	if(kq==1)
	{
		
		//int ip = Integer.parseInt(m_host);
		//ServerSocket serverSocket;
		String line = "";
		try {
		 DatagramSocket serverSocket = new DatagramSocket(i_port);
			byte[] receiveData = new byte[1024];
			DatagramPacket receivePacket = new DatagramPacket(receiveData,receiveData.length);
			serverSocket.receive(receivePacket);

			//serverSocket = new ServerSocket(i_port);
			//Socket client = serverSocket.;
			line = new String(receivePacket.getData());
			// BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
	       // line=in.readLine();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 if(line.equals("OK"))
		 {
	
		int ports = 8181;
			int kq1 = send.sendfilename(m_host, ports, m_filename);
			try {
				//Thread.sleep(2000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				tte.printStackTrace();
			}
			if(kq1!=0)
			{
				int portss = 8383;
			//	int kq2 = send.SendfilenameUDP(m_host, i_port, m_Content);
				int kq3 = send.SenContentFile(m_Path, m_filename, m_host, portss);
				thongbao = "successful"+kq3;
				
			}
			else
			{
				thongbao = "unsuccessful";
			}
		 }
	}
	//}
	
	
	return thongbao;
	
	
}


*/